<template>
  <div
    v-if="show"
    class="context-menu"
    :style="{ left: x + 'px', top: y + 'px' }"
    @click="$emit('hide')"
  >
    <div
      v-for="(item, index) in items"
      :key="index"
      class="context-menu-item"
      :class="{ divider: item.divider, disabled: item.disabled }"
      @click="item.action"
    >
      <el-icon v-if="item.icon"><component :is="item.icon" /></el-icon>
      <span>{{ item.label }}</span>
      <span v-if="item.shortcut" class="menu-shortcut">{{ item.shortcut }}</span>
    </div>
  </div>
</template>

<script setup>
defineProps({
  show: {
    type: Boolean,
    default: false
  },
  x: {
    type: Number,
    default: 0
  },
  y: {
    type: Number,
    default: 0
  },
  items: {
    type: Array,
    default: () => []
  }
})

defineEmits(['hide'])
</script>

<style scoped>
.context-menu {
  position: fixed;
  min-width: 220px;
  background: rgba(40, 40, 40, 0.98);
  backdrop-filter: blur(20px);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  z-index: 10000;
  animation: context-menu-show 0.15s ease;
}

@keyframes context-menu-show {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  color: white;
  font-size: 13px;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.2s;
}

.context-menu-item:hover:not(.divider):not(.disabled) {
  background: rgba(255, 255, 255, 0.1);
}

.context-menu-item.divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  margin: 4px 0;
  padding: 0;
  cursor: default;
}

.context-menu-item.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.menu-shortcut {
  margin-left: auto;
  font-size: 11px;
  opacity: 0.6;
}
</style>

